# -*- coding: utf-8 -*-

'''
Created on 26/11/2011

@author: Luis M. Ugalde
www.forondarena.net

Copyright © 2011 Luis M. Ugalde
Licensed under the terms of the MIT License
(see LICENSE file for details)

This software can't be considered to be even in Alpha state. It still needs a lot of work.
'''


import sys
from parsers.parserexception import ParserException


class Parser(object):
    '''
    Parser facade-like structural pattern.
    '''


    def __init__(self, parsertype, availableparsers, *args, **kwargs):
        '''
        self.availableclasses = {'Postfix': pspostfix.ParserPostfix
                        }
        '''
        
        self.availableclasses = availableparsers
        
        try:
            module, klass = self.availableclasses[parsertype].split(".")
            _tmpmodule = __import__(module, globals(), locals(), [], 1)
            self.parser = getattr(sys.modules['parsers.' + module], klass)(*args, **kwargs)
        except TypeError:
            raise ParserException('AbstractParser interface must be fully implemented')
        except KeyError:
            raise ParserException('Parser type is invalid')
        except ImportError:
            raise ParserException('Cant import required module')


    def setSource(self, *args, **kwargs):
        '''
        '''
        self.parser.setSource(*args, **kwargs)


    def connectSources(self, *args, **kwargs):
        '''
        '''
        self.parser.connectSources(*args, **kwargs)


    def setBindParser(self, *args, **kwargs):
        '''
        '''
        self.parser.setBindParser(*args, **kwargs)


    def bindParser(self, *args, **kwargs):
        '''
        '''
        self.parser.bindParser(*args, **kwargs)


    def setNotifySource(self, *args, **kwargs):
        '''
        '''
        self.parser.setNotifySource(*args, **kwargs)


    def connectNotifySources(self, *args, **kwargs):
        '''
        '''
        self.parser.connectNotifySources(*args, **kwargs)


    def setBindNotifyParser(self, *args, **kwargs):
        '''
        '''
        self.parser.setBindNotifyParser(*args, **kwargs)


    def bindNotifyParser(self, *args, **kwargs):
        '''
        '''
        self.parser.bindNotifyParser(*args, **kwargs)


    def parseLines(self, *args, **kwargs):
        '''
        '''
        self.parser.parseLines(*args, **kwargs)


if __name__ == '__main__':
    print "Please, do not run this"        
